package com.sjr.easy.chat.app.ws;

import com.alibaba.fastjson2.JSON;
import org.springframework.stereotype.Component;
import org.springframework.web.socket.TextMessage;
import org.springframework.web.socket.WebSocketSession;

import java.io.IOException;

@Component
public class EchoTextMessageProcessor implements TextMessageProcessor {
    @Override
    public void process(WebSocketSession session, TextMessage message, AppWSMessage appWSMessage) throws IOException {
        session.sendMessage(new TextMessage(JSON.toJSONString(appWSMessage)));
    }

    @Override
    public String getType() {
        return AppWSMessageTypeEnum.ECHO.getTypeName();
    }

    @Override
    public String toString() {
        return "EchoTextMessageProcessor{'echo'}";
    }
}
